<template>
  <div>
    <!-- 经销商名称\代码搜索 -->
    <TopFilter
      :list="topFilterInit"
      :cols="2"
      :collapse="collapse"
      labelWidth="90"
      @filterChange="changeHandle"
    ></TopFilter>
    <!-- table -->
    <FilterTable
      height="250"
      ref="listModal"
      :columns="columns"
      :selectionType="selectType"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :onColumnsChange="columns => this.columns = columns"
      :onRowSelectChange="selectChange"
  columnsRef="cms-common_dealerdata_index_01"      
    ></FilterTable>
    <div class="dialogBottmView">
      <el-button @click="closeDialog">取 消</el-button>
      <el-button @click="saveDialog" type="primary">确定</el-button>
    </div>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { getDealerList ,pageDealerInfoList ,getRegion, getCommunity} from '@/api/cms-common/dealerdata';
import { DICT_CODE } from '@/api/cms-api/origin/commonDealerType';		//经销商类型工具类
import { region } from '@/api/cms-common/region';//行政区域

export default {
  mixins: [dictionary,region],
  props: {
    value: {
      type: Object,
      required: true
    },
    selectType:{
      type: String,
      default: 'multiple'
    }
  },
  data() {
    return {
      excludeBigCustomer:this.value.excludeBigCustomer ? 25031004 : null,
      visible: false,
      visibleDrawer: false,
      collapse: false,
      infoId: null,
      topFilterInit: this.topFilterInitFun(),
      flterValue: {}, //参数
      columns: this.creatHeader(),
      fetchApi:pageDealerInfoList,
      fetchParams: {
        excludeBigCustomer: this.value.excludeBigCustomer ? 25031004 : null,
        isDeleted: 0,//未删除
        status:10031001,//启用
        auditStatus:25511005//已审核
      }, //ipa 接口
      selectedRows: []//选中经销商
    };
  },
  methods: {
    //搜索数据
    topFilterInitFun() {
      return [
        { type: 'SELECT', label: '事业部', fieldName: 'deptId', placeholder: '请选择', initialValue: '' ,itemList:[]},
        { type: 'INPUT', label: '经销商代码', fieldName: 'dealerCode', placeholder: '请输入', initialValue: '' },
        { type: 'INPUT', label: '经销商简称', fieldName: 'dealerShortname', placeholder: '请输入', initialValue: '' }
      ];
    },
    //搜索获取数据
    changeHandle(val) {
      let extP = {
        excludeBigCustomer: this.value.excludeBigCustomer ? 25031004 : null,
        isDeleted: 0,//未删除
        status:10031001,//启用
        auditStatus:25511005//已审核
      }
      this.fetchParams = Object.assign({},val,extP);
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        { title: '公司全称', dataIndex: 'dealerName', sorter: true },
        { title: '经销商代码', dataIndex: 'dealerCode', sorter: true },
        { title: '经销商简称', dataIndex: 'dealerShortname', sorter: true },
        { title: '经销商类型', dataIndex: 'dealerType', sorter: true, render: props => {
            return <span>{this.createDictText(props.row.dealerType, DICT_CODE)}</span>;
          } },
        { title: '经销商级别', dataIndex: 'shopLevel', sorter: true, render: props => {
            return <span>{this.createDictText(props.row.shopLevel, '2540')}</span>;
          } },
        { title: '事业部', dataIndex: 'deptName', sorter: true ,width:200},
        // { title: '省份', dataIndex: 'provinceId', sorter: true , render: props => {
        //     return <span>{this.createDictText(props.row.provinceId, '1056')}</span>;
        //   }},
        // { title: '城市', dataIndex: 'cityId', sorter: true ,render: props => {
        //     return <span>{this.createDictText(props.row.cityId, '1056')}</span>;
        //   }},
        // { title: '县区', dataIndex: 'countyId', sorter: true ,render: props => {
        //     return <span>{this.createDictText(props.row.countyId, '1056')}</span>;
        //   }}
          { title: '省份', dataIndex: 'provinceId', sorter: true,
						render: props => {
							return <span>{this.createRegionText(props.row.provinceId)}</span>;
						}
					},
					{ title: '城市', dataIndex: 'cityId', sorter: true,
						render: props => {
							return <span>{this.createRegionText(props.row.cityId)}</span>;
						}
					},
					{ title: '县区', dataIndex: 'districtId', sorter: true,
						render: props => {
							return <span>{this.createRegionText(props.row.districtId)}</span>;
						}
					}
      ];
    },
    //选中
    selectChange(rows) {
      this.selectedRows = rows;
      console.log(this.selectedRows);
    },
    //保存
    saveDialog() {
      console.log("excludeBigCustomer:"+this.excludeBigCustomer);
      if(this.selectedRows.length == 0){
        this.$notify.warning({ title: '提示信息', message: '请勾选经销商!' });
        return;
      }
      this.$emit('close', { visible: false ,"data":this.selectedRows});
    },
    //取消操作
    closeDialog() {
      // this.$emit('close', { visible: false ,"data":this.selectedRows});
      this.$emit('close', { visible: false });
    },
    //加载事业部数据
    async getDeptData() {
      const res = await getRegion({});
      if (res.resultCode === 200) {
        this.topFilterInit.find(item => item.fieldName === 'deptId').itemList = res.data.map(x => ({ value: x.id, text: x.orgName }));
      }
    }
  },
  mounted() {
    //this.BaseTable = this.$refs.listModal.$refs.pageTable;
    this.getDeptData();
  }
};
</script>

<style lang="less" scoped>
</style>
